/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* **********************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using OfficeOpenXMLInterop;

namespace Theme_Builder.Utility
{
    // TODO: This class isn't complete yet but it's intent is to eventually pull the read/write logic
    //  out of the Theme Builder project and into this utility project.

    /// <summary>
    /// Singleton class to manage access to reading/writing of a file
    /// </summary>
    public class OpenSave
    {
        private static OpenSave instance = null;        // the instance we'll be working within

        // Mutex to protect access to instance.  Not really needed just yet and this
        //  won't go 100% if/when it is, but it will help out if we ever decide to 
        //  thread this stuff.
        private static Mutex instanceMtx = new Mutex();

        private string filename;                        // filename we'll be reading/writing to/from
        private Mutex readWriteMtx;                     // not entirely needed yet, but just a precaution 

        // TODO: create a callback to query the user for saveas information

        private OpenSave()
        {
            this.filename = null;
            this.readWriteMtx = new Mutex();
        }

        /// <summary>
        /// Returns the single instance of this class
        /// </summary>
        public OpenSave Instance
        {
            get
            {
                if (instanceMtx.WaitOne())
                {
                    if (instance == null)
                        instance = new OpenSave();
                }

                instanceMtx.ReleaseMutex();

                return instance;
            }
        }

        public CT_OfficeStyleSheet ReadTheme(string filename)
        {
            return null;
        }

        public void WriteTheme(string filename, CT_OfficeStyleSheet styleSheet)
        {
        }
    }
}
